home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / Waste TCL r2 / CWASTEText.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-30  |  36.0 KB  |  1,545 lines  |  [TEXT/KAHL]

  1. /********************************************************\
  2.  CWASTEText.cpp
  3.  
  4. version 1.1 
  5.  
  6. \********************************************************/
  7.  
  8. #ifdef TCL_PCH
  9. #include <TCLHeaders>
  10. #endif
  11.  
  12. #include "CWASTEText.h"
  13. #include "CWASTEEditTask.h"
  14. #include "CWASTEStyleTask.h"
  15.  
  16. #ifndef __ERRORS__
  17. #include <Errors.h>
  18. #endif
  19. #ifndef __SCRAP__
  20. #include <Scrap.h>
  21. #endif
  22. #ifndef __FONTS__
  23. #include <Fonts.h>
  24. #endif
  25.  
  26. #include <Script.h>
  27. #include "CClipboard.h"
  28. #include "CBartender.h"
  29. #include "Commands.h"
  30. #include "TCLUtilities.h"
  31. #include "Constants.h"
  32. #include "CScrollPane.h"
  33. #include "Global.h"
  34. #include <TextServices.h>
  35. #include "CPrinter.h"
  36.  
  37. // Global Variables
  38. extern CClipboard    *gClipboard;    // Copies and Pastes data
  39. extern EventRecord  gLastMouseUp;
  40. extern CBureaucrat    *gGopher;
  41. extern CBartender    *gBartender;
  42.  
  43. extern long            gSleepTime;
  44. extern short        gUsingTSM;
  45.  
  46. static pascal Boolean WEClickLoop(WEHandle hWE);
  47. static pascal void WEPreUpdate(WEHandle hWE);
  48.  
  49. CWASTEText    *gWASTEText=NULL;                /* Current WASTEText object */
  50.  
  51. // undocumented WASTE routine
  52. #define CWASTE
  53. #ifdef CWASTE
  54. extern "C"
  55. {
  56.     long _WEOffsetToLine(long offset, WEHandle hWE);
  57. }
  58. #else
  59.     pascal long _WEOffsetToLine(long offset, WEHandle hWE);
  60. #endif
  61. // undocumented WASTE feature flag
  62. const short weFActive = 20;
  63.  
  64. TCL_DEFINE_CLASS_D1(CWASTEText, CAbstractText);
  65.  
  66. /********************************************************\
  67.  CWASTEText() - default constructor
  68.      You must call IWASTEText if you use this
  69. \********************************************************/
  70.  
  71. CWASTEText::CWASTEText()
  72. {
  73.     macWE = NULL;
  74.     spacingCmd = cmdSingleSpace;
  75.     alignCmd = cmdAlignLeft;
  76.  
  77.     wholeLines = false;
  78.     
  79.     fixedLineHeights = false;
  80.     
  81.     TCL_END_CONSTRUCTOR
  82. }
  83.  
  84. /********************************************************\
  85.  CWASTEText - constructor
  86.      You cannot call IWASTEText if you use this
  87. \********************************************************/
  88.  
  89. CWASTEText::CWASTEText(
  90.     CView            *anEnclosure,
  91.     CBureaucrat        *aSupervisor,
  92.     short            aWidth,
  93.     short            aHeight,
  94.     short            aHEncl,
  95.     short            aVEncl,
  96.     SizingOption    aHSizing,
  97.     SizingOption    aVSizing,
  98.     short            aLineWidth,
  99.     Boolean            aScrollHoriz,
  100.     TextStyle         *tStyle)
  101.  
  102.     :    CAbstractText(anEnclosure, aSupervisor,
  103.                      aWidth, aHeight, aHEncl, aVEncl, aHSizing, aVSizing,
  104.                      aLineWidth, aScrollHoriz)
  105. {
  106.     macWE = NULL;
  107.     spacingCmd = cmdSingleSpace;
  108.     alignCmd = cmdAlignLeft;
  109.  
  110.     wholeLines = false;
  111.     fixedLineHeights = false;
  112.  
  113.     if (tStyle)
  114.     {
  115.         TextFont(tStyle->tsFont);
  116.         TextSize(tStyle->tsSize);
  117.         TextFace(tStyle->tsFace);
  118.         if (gSystem.hasColorQD)
  119.             RGBForeColor(&tStyle->tsColor);
  120.     }
  121.  
  122.     
  123.     IWASTETextX();
  124.     TCL_END_CONSTRUCTOR
  125. }
  126.  
  127. /********************************************************\
  128.  ~CWASTEText - destructor
  129. \********************************************************/
  130.  
  131. CWASTEText::~CWASTEText()
  132. {
  133.     TCL_START_DESTRUCTOR
  134.     if (macWE)
  135.     {
  136.         WEDispose(macWE);
  137.         macWE = NULL;
  138.     }
  139. }
  140.  
  141. /********************************************************\
  142.  IWASTEText - initialize CWASTEText
  143.      Use this only if you use the default constructor
  144. \********************************************************/
  145.  
  146. void CWASTEText::IWASTEText(
  147.     CView            *anEnclosure,
  148.     CBureaucrat        *aSupervisor,
  149.     short            aWidth,
  150.     short            aHeight,
  151.     short            aHEncl,
  152.     short            aVEncl,
  153.     SizingOption    aHSizing,
  154.     SizingOption    aVSizing,
  155.     short            aLineWidth,
  156.     TextStyle         *tStyle)
  157. {
  158.  
  159.     CAbstractText::IAbstractText(anEnclosure, aSupervisor,
  160.                      aWidth, aHeight, aHEncl, aVEncl, aHSizing, aVSizing,
  161.                      aLineWidth);
  162.     if (tStyle)
  163.     {
  164.         TextFont(tStyle->tsFont);
  165.         TextSize(tStyle->tsSize);
  166.         TextFace(tStyle->tsFace);
  167.         if (gSystem.hasColorQD)
  168.             RGBForeColor(&tStyle->tsColor);
  169.     }
  170.  
  171.     IWASTETextX();
  172. }
  173.  
  174. /********************************************************\
  175.  IViewTemp - initialize from View resource
  176. \********************************************************/
  177.  
  178. void CWASTEText::IViewTemp(CView *anEnclosure, CBureaucrat *aSupervisor,
  179.                         Ptr viewData)
  180. {
  181.     CAbstractText::IViewTemp(anEnclosure, aSupervisor, viewData);
  182.  
  183.     macWE = NULL;
  184.     spacingCmd = cmdSingleSpace;
  185.     alignCmd = cmdAlignLeft;
  186.     fixedLineHeights = FALSE;
  187.  
  188.     IWASTETextX();
  189. }
  190.  
  191. /********************************************************\
  192.  IWASTETextX - initialization common to above routines
  193. \********************************************************/
  194.  
  195. void CWASTEText::IWASTETextX()
  196. {
  197.     LongRect            tLongFrame;
  198.     WEClickLoopProcPtr    clickLoop;
  199.     Boolean                saveAllocState;
  200.     OSErr                err;
  201.     WETSMPreUpdateProcPtr preProc;
  202.     WEHandle             newMacWE;
  203.  
  204.     ForceNextPrepare();
  205.  
  206.     UseLongCoordinates(TRUE);
  207.  
  208.     // Figure out size of of rectangle
  209.     GetAperture(&tLongFrame);
  210.  
  211.     // create WEHandle
  212.     saveAllocState = SetAllocation(kAllocCanFail);
  213.     err = WENew(&tLongFrame, &tLongFrame, weDoOutlineHilite + weDoDrawOffscreen,
  214.                  &newMacWE);
  215.     SetAllocation(saveAllocState);
  216.     FailOSErr(err);
  217.     macWE = newMacWE;
  218.  
  219.     SetWholeLines(wholeLines);
  220.  
  221.     AdjustBounds();
  222.  
  223.     autoRefresh = lineWidth <= 0;
  224.  
  225.     preProc = &WEPreUpdate;
  226.     WESetInfo(weTSMPreUpdate, (Ptr)&preProc, macWE);
  227.  
  228.     clickLoop = &WEClickLoop;
  229.     WESetInfo(weClickLoop, (Ptr)&clickLoop, macWE);
  230.     CalcWERects();
  231.     if (lineWidth < 0)
  232.     {
  233.         saveAllocState = SetAllocation(kAllocCanFail);
  234.         err = WECalText( macWE);
  235.         SetAllocation(saveAllocState);
  236.     }
  237. }
  238.  
  239. /********************************************************\
  240.  CheckInsertion -- sees if it is possible to insert
  241.  text
  242. \********************************************************/
  243.  
  244. void CWASTEText::CheckInsertion(long numChars, long styleSize, Boolean useSelection)
  245. {
  246.     long    selStart, selEnd;
  247.     long    growSize = numChars;
  248.     Handle    h;
  249.     OSErr    err;
  250.  
  251.     if (useSelection)
  252.     {
  253.         GetSelection(&selStart, &selEnd);
  254.         growSize -= Abs(selEnd - selStart);
  255.     }
  256.  
  257.     /*    The problem with WASTE is that it can succeed in adding the text to its content
  258.      *    structure, and then fail to expand its style tables or line start tables.  The way
  259.      *    I address this is to add a fudge factor to the amount of data being added, and
  260.      *    hope that its enough to cover the WASTE overhead.
  261.      */
  262.  
  263.     if (growSize > 0)
  264.     {
  265.         /*    Add fudge factor for new line starts (1/5th of numChars)    */
  266.         
  267.         growSize += growSize / 5;
  268.         
  269.         /*    Add fudge factor for style information (1/2 of styleSize)    */
  270.  
  271.         growSize += styleSize + styleSize / 2;
  272.  
  273.         if (WEFeatureFlag(weFUseTempMem, weBitTest, macWE))
  274.         {
  275.             h = TempNewHandle(growSize, &err);
  276.             if (!h && err == noErr)
  277.                 err = memFullErr;
  278.             DisposeHandle(h);
  279.             FailOSErr(err);
  280.         }
  281.         else
  282.         {
  283.             h = NewHandleCanFail(growSize);
  284.             FailNIL(h);
  285.             DisposeHandle(h);
  286.         }
  287.     }
  288. }
  289.  
  290.  
  291. /********************************************************\
  292.  WEPreUpdate -- prepare the port
  293. \********************************************************/
  294.  
  295. static pascal void WEPreUpdate(WEHandle hWE)
  296. {
  297.     if (gWASTEText != NULL)
  298.     {
  299.         gWASTEText->Prepare();
  300.     }
  301. }
  302.  
  303.  
  304. /********************************************************\
  305.  DoClick - handle mouse clicks
  306. \********************************************************/
  307.  
  308. void CWASTEText::DoClick(Point hitPt, short modifierKeys, long when)
  309. {
  310.  
  311.         // Handle the mouse click
  312.  
  313.     WEClick(hitPt, modifierKeys, when, macWE);
  314.     
  315.         // CSwitchboard will never see the mouse up that ended
  316.         // the drag, so we stuff gLastMouseUp here to allow
  317.         // multi-click counting to work.
  318.         
  319.     gLastMouseUp.what = mouseUp;
  320.     gLastMouseUp.when = TickCount();
  321.     gLastMouseUp.where = hitPt;
  322.     LocalToGlobal( &gLastMouseUp.where);
  323.     gLastMouseUp.modifiers = modifierKeys;
  324.  
  325.     SelectionChanged();
  326.     
  327.     if (!editable && (gGopher == this))
  328.     {
  329.         long selStart, selEnd;
  330.         
  331.         GetSelection( &selStart, &selEnd);    
  332.         if (selStart == selEnd)
  333.             itsSupervisor->BecomeGopher( TRUE);
  334.     }
  335. }
  336.  
  337.  
  338. /********************************************************\
  339.  UpdateMenus - handle WASTE specific menu enabling
  340. \********************************************************/
  341.  
  342. void CWASTEText::UpdateMenus()
  343. {
  344.     long    selStart, selEnd;
  345.  
  346.     inherited::UpdateMenus();
  347.     
  348.         // Copy and Cut are only possible if the selection is small (< 32K).
  349.         // The danger here is that a piece of styled text > 32K will pass
  350.         // through the clipboard to another applciation which cannot handle
  351.         // it (like the Finder).
  352.         //
  353.         // Should probably override DoCommand as well to make sure a command
  354.         // does not get past the Menu Manager -- can be done later.
  355.     
  356.     GetSelection(&selStart, &selEnd);
  357.     if (Abs(selEnd - selStart) >= 32767)
  358.     {
  359.         gBartender->DisableCmd(cmdCopy);
  360.         gBartender->DisableCmd(cmdCut);
  361.     }
  362. }
  363.  
  364. /********************************************************\
  365.  MakeEditTask -- use WASTE specific one
  366. \********************************************************/
  367.  
  368. CTextEditTask *CWASTEText::MakeEditTask( long editCmd)
  369. {
  370.     CWASTEEditTask *volatile editTask = NULL;
  371.     
  372.     try_
  373.     {
  374.         editTask = new CWASTEEditTask(this, editCmd, cFirstTaskIndex);
  375.     }
  376.  
  377.     catch_all_()
  378.     {
  379.         TCLForgetObject(editTask);
  380.  
  381.         throw_same_();
  382.     }
  383.     end_try_
  384.     
  385.     return editTask;
  386. }
  387.  
  388. /********************************************************\
  389.  MakeStyleTask -- use WASTE specific one
  390. \********************************************************/
  391.  
  392.  
  393. CTextStyleTask *CWASTEText::MakeStyleTask( long styleCmd)
  394. {
  395.  
  396.     CWASTEStyleTask *volatile newTask = NULL;
  397.     short            taskIndex;
  398.     
  399.     try_
  400.     {
  401.         taskIndex = cFirstTaskIndex > 0 ? cFirstTaskIndex + undoFormatting : 0;
  402.         newTask = new CWASTEStyleTask(this, styleCmd, taskIndex);
  403.     }
  404.  
  405.     catch_all_()
  406.     {
  407.         TCLForgetObject( newTask);
  408.  
  409.         throw_same_();
  410.     }
  411.     end_try_
  412.     
  413.     return newTask;
  414. }
  415.  
  416.  
  417. /********************************************************\
  418.  PerformEditCommand - handle cut, copy, paste, and clear
  419. \********************************************************/
  420.  
  421. void CWASTEText::PerformEditCommand(long theCommand)
  422. {
  423.     Boolean        saveAllocState;
  424.     OSErr        err = noErr;
  425.  
  426.     Prepare();
  427.     if (!ReallyVisible())
  428.         SetOrigin(-10000, -10000);
  429.  
  430.     switch( theCommand)
  431.     {        
  432.         case cmdCut:
  433.             gClipboard->EmptyGlobalScrap();
  434.             saveAllocState = SetAllocation(kAllocCanFail);        
  435.             err = WECut(macWE);
  436.             SetAllocation(saveAllocState);
  437.             if (err == noErr)
  438.                 gClipboard->UpdateDisplay();
  439.             break;
  440.             
  441.         case cmdCopy:
  442.             gClipboard->EmptyGlobalScrap();
  443.             saveAllocState = SetAllocation(kAllocCanFail);        
  444.             err = WECopy(macWE);
  445.             SetAllocation(saveAllocState);
  446.             if (err == noErr)
  447.                 gClipboard->UpdateDisplay();
  448.             break;
  449.             
  450.         case cmdPaste:
  451.             CheckInsertion(gClipboard->DataSize('TEXT'),
  452.                            gClipboard->DataSize('styl'), TRUE);
  453.             saveAllocState = SetAllocation(kAllocCanFail);
  454.             err = WEPaste(macWE);
  455.             SetAllocation(saveAllocState);
  456.             break;
  457.             
  458.         case cmdClear:
  459.             saveAllocState = SetAllocation(kAllocCanFail);        
  460.             err = WEDelete(macWE);
  461.             SetAllocation(saveAllocState);
  462.             break;
  463.             
  464.     }
  465.     AdjustBounds();
  466.     ScrollToSelection();
  467.     FailOSErr(err);
  468. }
  469.  
  470.  
  471. /********************************************************\
  472.  Draw - draw the text
  473. \********************************************************/
  474.  
  475. void CWASTEText::Draw(Rect *area)
  476. {
  477.     RgnHandle    updateRgn;
  478.     LongRect    fr, dr;
  479.     Rect        r;
  480.     
  481.     if (!ReallyVisible())
  482.         return;
  483.  
  484.     updateRgn = NewRgn();
  485.     RectRgn(updateRgn, area);
  486.     SectRgn(updateRgn, macPort->visRgn, updateRgn);
  487.     
  488.     if (!printing)
  489.         CalcWERects();
  490.     else
  491.     {
  492.         // Prepare the destination and view rectangles
  493.  
  494.         WEGetDestRect(&dr, macWE);
  495.         GetAperture(&fr);
  496.         OffsetLongRect(&dr, -(dr.left + fr.left), -(dr.top + fr.top));
  497.         FrameToQDR(&fr, &r);
  498.         OffsetLongRect(&dr, r.left, r.top);
  499.         dr.right = (lineWidth > 0) ? dr.left + lineWidth : printPageWidth;
  500.         WESetDestRect(&dr, macWE);
  501.         QDToLongRect(area, &fr);
  502.         if (wholeLines)
  503.             fr.bottom = fr.top + vScale * ((area->bottom - area->top) / vScale);
  504.         WESetViewRect(&fr, macWE);
  505.     }
  506.  
  507.     WEUpdate(updateRgn, macWE);
  508.     // not necessary -- err = WESetInfo(wePort, &macPort, macWE);
  509.     DisposeRgn(updateRgn);
  510.  
  511. }
  512.  
  513.  
  514. /********************************************************\
  515.  Activate - activate the pane
  516. \********************************************************/
  517.  
  518. void CWASTEText::Activate()
  519. {
  520.     TSMDocumentID aTSMDocument;
  521.     
  522.     if (gWASTEText==this) // already active
  523.     {
  524.         return;
  525.     }
  526.     
  527.     CAbstractText::Activate();
  528.     
  529.     // deactivate old WASTEText
  530.     if (gWASTEText!=NULL) gWASTEText->Deactivate();
  531.     Prepare();
  532.     CalcWERects();
  533.     WEActivate(macWE);
  534.     gWASTEText = this;
  535.     if (!editable)
  536.     {
  537.         // if not editable, deactivate TSM so inline input won't work
  538.         if (gUsingTSM)
  539.         {
  540.             if (WEGetInfo(weTSMDocumentID, (Ptr)&aTSMDocument, macWE) == noErr)
  541.             {
  542.                 if (aTSMDocument != NULL)
  543.                     DeactivateTSMDocument(aTSMDocument);
  544.             }
  545.         }
  546.     }
  547. }
  548.  
  549. /********************************************************\
  550.  Deactivate - deactivate the pane
  551. \********************************************************/
  552.  
  553. void CWASTEText::Deactivate()
  554. {
  555.     CAbstractText::Deactivate();
  556.  
  557.     Prepare();
  558.     WEStopInlineSession(macWE);
  559.     if (macWE)
  560.     {
  561.         CalcWERects();
  562.         WEDeactivate(macWE);
  563.     }
  564.     gWASTEText = NULL;
  565. }
  566.  
  567. /********************************************************\
  568.  SetSelection - set what text is selected
  569. \********************************************************/
  570.  
  571. void CWASTEText::SetSelection(long selStart, long selEnd, Boolean fRedraw)
  572. {
  573.     short wasActive, wasOutline;
  574.  
  575.     Prepare();    
  576.     if (!fRedraw)
  577.     {
  578.         wasActive = WEFeatureFlag(weFActive, weBitClear, macWE);
  579.         wasOutline = WEFeatureFlag(weFOutlineHilite, weBitClear, macWE);
  580.     }
  581.     WESetSelection(selStart, selEnd, macWE);
  582.     if (!fRedraw)
  583.     {
  584.         WEFeatureFlag(weFActive, wasActive, macWE);
  585.         WEFeatureFlag(weFOutlineHilite, wasOutline, macWE);
  586.     }
  587. }
  588.  
  589. /********************************************************\
  590.  Clear - clear the text
  591.     Deactivates text before clearing to prevent
  592.     highlighting from showing up
  593. \********************************************************/
  594.  
  595. void CWASTEText::Clear(void)
  596. {
  597.     Boolean    saveAllocState;
  598.     OSErr    err;
  599.     
  600.     // select all temporarily
  601.     //TempSelectAll();
  602.     SetSelection(0, 0x7FFFFFFF, false);
  603.     saveAllocState = SetAllocation(kAllocCanFail);
  604.     err = WEDelete(macWE);
  605.     SetAllocation(saveAllocState);
  606.     
  607.     //RestoreSelection();
  608.     AdjustBounds();
  609.     ScrollToSelection();
  610.     FailOSErr(err);
  611. }
  612.  
  613. /********************************************************\
  614.  SetTextPtr - set the text to a block of memory
  615. \********************************************************/
  616.  
  617. void CWASTEText::SetTextPtr(Ptr textPtr, long numChars)
  618. {
  619.     Boolean        saveAllocState;
  620.     OSErr        err;
  621.     Handle newHand;
  622.  
  623.     Prepare();
  624.     if (!ReallyVisible())
  625.         SetOrigin(-10000, -10000);
  626.     
  627.     SetSelection(0, 0x7FFFFFFF, false);
  628.     FailOSErr(WEDelete(macWE));
  629.     CheckInsertion(numChars, 0, FALSE);
  630.     saveAllocState = SetAllocation(kAllocCanFail);
  631.     err = WEInsert(textPtr, numChars, NULL, macWE);
  632.     SetAllocation(saveAllocState);
  633.  
  634.     AdjustBounds();
  635.     Refresh();
  636.     
  637.     FailOSErr(err);
  638. }
  639.  
  640. /********************************************************\
  641.  StopInlineSession - stop inline session, confirm text
  642. \********************************************************/
  643.  
  644. void CWASTEText::StopInlineSession(void)
  645. {
  646.     WEStopInlineSession(macWE);
  647. }
  648.  
  649. /********************************************************\
  650.  SetOutlineHighliting - turns on or off outline
  651.      highliting and returns old setting
  652. \********************************************************/
  653.  
  654. Boolean CWASTEText::SetOutlineHighliting(Boolean hilite)
  655. {
  656.     Boolean oldValue;
  657.     
  658.     oldValue = (WEFeatureFlag(weFOutlineHilite, 
  659.         hilite ? weBitSet : weBitClear, macWE) == weBitSet);
  660.         
  661.     return oldValue;
  662. }
  663.  
  664. /********************************************************\
  665.  GetTextHandle - get a handle to the text
  666.      This is not a copy of the handle, but the real thing
  667. \********************************************************/
  668.  
  669. Handle CWASTEText::GetTextHandle()
  670. {
  671.     return( (Handle) WEGetText(macWE));
  672. }
  673.  
  674. /********************************************************\
  675.  CopyTextRange - return a handle to a copy of the
  676.      indicated range of text
  677. \********************************************************/
  678.  
  679. Handle CWASTEText::CopyTextRange(long start, long end)
  680. {
  681.     Handle    h;
  682.     long    len;
  683.     
  684.     end = Min(end, WEGetTextLength(macWE));
  685.     
  686.     len = Max(end - start, 0);
  687.     h = NewHandleCanFail(len);
  688.     FailNIL(h);
  689.     if (len > 0)
  690.         BlockMove( (char*)*(WEGetText(macWE)) + start, *h, len);
  691.     
  692.     return h;
  693. }
  694.  
  695. /********************************************************\
  696.  CopyRangeWithStyle - return a handle to the text and
  697.      styles in a range.  Handles must be previously
  698.      created with NewHandle();
  699. \********************************************************/
  700.  
  701. void CWASTEText::CopyRangeWithStyle(long start, long end, Handle hText,
  702.     StScrpHandle hStyles)
  703. {
  704.     Boolean        saveAllocState;
  705.     OSErr        err;
  706.     
  707.     saveAllocState = SetAllocation(kAllocCanFail);
  708.     err = WECopyRange(start, end, hText, hStyles, macWE);
  709.     SetAllocation(saveAllocState);
  710.     FailOSErr(err);
  711. }
  712.  
  713. /********************************************************\
  714.  InsertTextPtr - insert a block of text
  715. \********************************************************/
  716.  
  717. void CWASTEText::InsertTextPtr(Ptr text, long length, Boolean fRedraw)
  718. {
  719.     Boolean        saveAllocState;
  720.     OSErr        err;
  721.  
  722.     Prepare();
  723.     if (!ReallyVisible())
  724.         SetOrigin(-10000, -10000);
  725.     CheckInsertion(length, 0, TRUE);
  726.     saveAllocState = SetAllocation(kAllocCanFail);
  727.     err = WEInsert(text, length, NULL, macWE);
  728.     SetAllocation(saveAllocState);
  729.  
  730.     AdjustBounds();
  731.     if (fRedraw) Refresh();
  732.     FailOSErr(err);
  733. }
  734.  
  735. /********************************************************\
  736.  InsertWithStyle -- insert text along with style
  737. \********************************************************/
  738.  
  739. void CWASTEText::InsertWithStyle(Ptr text, long length, StScrpHandle hStyles,
  740.         Boolean fRedraw)
  741. {
  742.     Boolean        saveAllocState;
  743.     OSErr        err;
  744.     long        i, numStyles;
  745.     short        fontSize;
  746.     StScrpPtr    styles;
  747.  
  748.     Prepare();
  749.     if (!ReallyVisible())
  750.         SetOrigin(-10000, -10000);
  751.     CheckInsertion(length, hStyles ? GetHandleSize((Handle) hStyles) : 0, TRUE);
  752.  
  753.     /*    Fix style entries which have a font size of 0    */
  754.     
  755.     if (hStyles)
  756.     {
  757.         //fontSize = LMGetSysFontSize(); // for some reason this is returning 0 also
  758.         fontSize = 12;
  759.         styles = *hStyles;
  760.         
  761.         numStyles = styles->scrpNStyles;
  762.         for (i = 0; i < numStyles; i++)
  763.             if (styles->scrpStyleTab[i].scrpSize == 0)
  764.                 styles->scrpStyleTab[i].scrpSize = fontSize;
  765.     }
  766.  
  767.     saveAllocState = SetAllocation(kAllocCanFail);
  768.     err = WEInsert(text, length, hStyles, macWE);
  769.     SetAllocation(saveAllocState);
  770.  
  771.     AdjustBounds();
  772.     if (fRedraw) Refresh();
  773.     FailOSErr(err);
  774. }
  775.  
  776. /********************************************************\
  777.  TypeChar - type a character
  778. \********************************************************/
  779.  
  780. void CWASTEText::TypeChar(char theChar, short theModifers)
  781. {
  782.     Boolean        saveAllocState;
  783.  
  784.     Prepare();
  785.     CheckInsertion(1, 0, TRUE);
  786.     saveAllocState = SetAllocation(kAllocCanFail);
  787.     WEKey(theChar, theModifers, macWE);
  788.     SetAllocation(saveAllocState);
  789.     AdjustBounds();
  790.     ScrollToSelection();
  791. }
  792.  
  793. /********************************************************\
  794.  CalcWERects - Sets the DestRect and ViewRect fields
  795.      used by WASTE
  796. \********************************************************/
  797.  
  798. void CWASTEText::CalcWERects()
  799. {
  800.     LongRect    fr, dr;
  801.     Rect        r;
  802.  
  803.         // Prepare the destination and view rectangles
  804.  
  805.     WEGetDestRect(&dr, macWE);
  806.     GetAperture(&fr);
  807.     OffsetLongRect(&dr, -(dr.left + fr.left), -(dr.top + fr.top));
  808.     FrameToQDR(&fr, &r);
  809.     OffsetLongRect(&dr, r.left, r.top);
  810.     dr.right = (lineWidth > 0) ? dr.left + lineWidth : fr.right;
  811.     WESetDestRect(&dr, macWE);
  812.     QDToLongRect(&r, &fr);
  813.     WESetViewRect(&fr, macWE);
  814. }
  815.  
  816. /********************************************************\
  817.  ResizeFrame - resize the frame when the size of the
  818.      pane changes
  819. \********************************************************/
  820.  
  821. void CWASTEText::ResizeFrame(Rect *delta)
  822. {
  823.     Boolean        saveAllocState;
  824.     OSErr        err;
  825.  
  826.     CAbstractText::ResizeFrame(delta);
  827.  
  828.     CalcWERects();    
  829.     if (lineWidth < 0)
  830.     {
  831.         saveAllocState = SetAllocation(kAllocCanFail);
  832.         err = WECalText( macWE);
  833.         SetAllocation(saveAllocState);
  834.         CalcWERects();
  835.     }
  836.     AdjustBounds();
  837. }
  838.  
  839. /********************************************************\
  840.  AdjustBounds - change the size of the CWASTEText to
  841.      match that in the WASTE record
  842. \********************************************************/
  843.  
  844. void CWASTEText::AdjustBounds()
  845. {
  846.     LongRect    oldBounds;
  847.     long          newHeight;
  848.     long        hFix = 0, vFix = 0;
  849.  
  850.     oldBounds = bounds;
  851.     newHeight = GetHeight(0, MAXINT);
  852.     
  853.     bounds.left = bounds.top = 0;
  854.     bounds.bottom = newHeight;
  855.  
  856.     if (lineWidth > 0) 
  857.     {
  858.         bounds.right = lineWidth;
  859.     } else {
  860.         bounds.right = frame.right - frame.left;
  861.     }
  862.         
  863.     bounds.right = (bounds.right - 1) / hScale + 1;
  864.  
  865.     /*    Deal with the possibility that the new bounds is smaller than the older one,
  866.      *    that the old position is now outside the bounds.
  867.      */
  868. /*
  869.     if (position.h > bounds.right)
  870.         hFix = bounds.right - oldBounds.right;
  871.     if (position.v > bounds.bottom)
  872.         vFix = bounds.bottom - oldBounds.bottom;
  873.     if (hFix || vFix)
  874.         Scroll(hFix, vFix, TRUE);
  875. */
  876.     if (itsScrollPane != NULL)
  877.     {
  878.         itsScrollPane->AdjustScrollMax();
  879.         itsScrollPane->Calibrate();
  880.     }
  881. }
  882.  
  883. /********************************************************\
  884.  FindLine - return the line on which the character
  885.      at charPos is on.
  886. \********************************************************/
  887.  
  888. long CWASTEText::FindLine(long charPos)
  889. {
  890.     long    lineNo;
  891.     
  892.     lineNo = _WEOffsetToLine(charPos, macWE);
  893.     if (charPos == WEGetTextLength(macWE) && 
  894.         ((char*)(*GetTextHandle()))[GetLength()-1] == 13)
  895.         lineNo++;
  896.  
  897.     return (lineNo);
  898.     
  899. }
  900.  
  901. /********************************************************\
  902.  GetLength - return the length of the text
  903. \********************************************************/
  904.  
  905. long CWASTEText::GetLength()
  906. {
  907.     return WEGetTextLength(macWE);
  908. }
  909.  
  910. /********************************************************\
  911.  SetFontNumber - set the font of the selection
  912. \********************************************************/
  913.  
  914. void CWASTEText::SetFontNumber(short aFontNumber)
  915. {
  916.     TextStyle    style;
  917.     
  918.     style.tsFont = aFontNumber;
  919.     SetStyle( doFont, &style, TRUE);
  920.  
  921. }
  922.  
  923. /********************************************************\
  924.  SetFontNumberAll - set the font of all of the text
  925. \********************************************************/
  926.  
  927. void CWASTEText::SetFontNumberAll(short aFontNumber)
  928. {
  929.     TempSelectAll();
  930.     SetFontNumber(aFontNumber);
  931.     RestoreSelection();
  932. }
  933.  
  934. /********************************************************\
  935.  SetFontNameAll - set the font of the selection
  936. \********************************************************/
  937.  
  938. void CWASTEText::SetFontNameAll(Str255 aFontName)
  939. {
  940.     TempSelectAll();
  941.     SetFontName(aFontName);
  942.     RestoreSelection();
  943. }
  944.  
  945. /********************************************************\
  946.  SetFontStyle - set the font style of the selection
  947. \********************************************************/
  948.  
  949. void CWASTEText::SetFontStyle(short aStyle)
  950. {
  951.     TextStyle    style;
  952.     short        mode = doFace;
  953.     
  954.     style.tsFace = aStyle;
  955.     if (aStyle != NOTHING)
  956.         mode += doToggle;
  957.     SetStyle( mode, &style, TRUE);
  958. }
  959.  
  960. /********************************************************\
  961.  SetFontStyleAll - set the font style of all of the text
  962. \********************************************************/
  963.  
  964. void CWASTEText::SetFontStyleAll(short aStyle)
  965. {
  966.     TempSelectAll();
  967.     SetFontStyle(aStyle);
  968.     RestoreSelection();
  969. }
  970.  
  971. /********************************************************\
  972.  SetFontSize - set the font size of the selection
  973. \********************************************************/
  974.  
  975. void CWASTEText::SetFontSize(short aSize)
  976. {
  977.     TextStyle    style;
  978.     
  979.     style.tsSize = aSize;
  980.     SetStyle( doSize, &style, TRUE);
  981. }
  982.  
  983. /********************************************************\
  984.  SetFontSizeAll - set the font size of all of the text
  985. \********************************************************/
  986.  
  987. void CWASTEText::SetFontSizeAll(short aSize)
  988. {
  989.     TempSelectAll();
  990.     SetFontSize(aSize);
  991.     RestoreSelection();
  992. }
  993.  
  994. /********************************************************\
  995.  SetTextMode - currently not implemented
  996. \********************************************************/
  997.  
  998. void CWASTEText::SetTextMode(short aMode)
  999. {
  1000.     return;
  1001. }
  1002.  
  1003. /********************************************************\
  1004.  SetAlignment - set the alignment
  1005. \********************************************************/
  1006.  
  1007. void CWASTEText::SetAlignment(short anAlignment)
  1008. {
  1009.     WESetAlignment(anAlignment, macWE);
  1010.     Refresh();
  1011. }
  1012.  
  1013. /********************************************************\
  1014.  SetAlignCmd - set the alignment
  1015. \********************************************************/
  1016.  
  1017. void CWASTEText::SetAlignCmd(long anAlignCmd)
  1018. {
  1019.     short teAlign;
  1020.     
  1021.     alignCmd = anAlignCmd;
  1022.     switch( alignCmd)
  1023.     {
  1024.         case cmdAlignLeft:
  1025.             teAlign = weFlushLeft;
  1026.             break;
  1027.         case cmdAlignCenter:
  1028.             teAlign = weCenter;
  1029.             break;
  1030.         case cmdAlignRight:
  1031.             teAlign = weFlushRight;
  1032.             break;
  1033.         default:
  1034.             teAlign = weFlushDefault;
  1035.     }
  1036.     SetAlignment(teAlign);
  1037. }
  1038.  
  1039. /********************************************************\
  1040.  SetSpacingCmd - not really supported
  1041. \********************************************************/
  1042.  
  1043. void CWASTEText::SetSpacingCmd(long aSpacingCmd)
  1044. {
  1045.     spacingCmd = cmdSingleSpace;
  1046.     
  1047.     // only single-spaced text is supported.
  1048.     
  1049.     SetWholeLines(wholeLines);
  1050.      CalcAperture();
  1051.     AdjustBounds();
  1052.  
  1053. }
  1054.  
  1055. /********************************************************\
  1056.  SetTheStyleScrap - set the style of a given range
  1057.      caller disposes handle
  1058. \********************************************************/
  1059.  
  1060. void CWASTEText::SetTheStyleScrap(long rangeStart, long rangeEnd,
  1061.             StScrpHandle styleScrap, Boolean redraw)
  1062. {
  1063.     Boolean        saveAllocState;
  1064.     OSErr        err;
  1065.     long        selStart, selEnd;
  1066.     
  1067.     Prepare();
  1068.     if (!ReallyVisible())
  1069.         SetOrigin(-10000, -10000);
  1070.     saveAllocState = SetAllocation(kAllocCanFail);
  1071.     WEGetSelection(&selStart, &selEnd, macWE);
  1072.     SetSelection(rangeStart, rangeEnd, FALSE);
  1073.     err = WEUseStyleScrap(styleScrap, macWE);
  1074.     if (err == noErr)
  1075.     {
  1076.         SetSelection(selStart, selEnd, false);
  1077.         err = WECalText( macWE);
  1078.     }
  1079.  
  1080.     SetAllocation(saveAllocState);
  1081.     AdjustBounds();
  1082.     FailOSErr(err);
  1083. }
  1084.  
  1085. /********************************************************\
  1086.  SetStyle - set the style of the current selection
  1087. \********************************************************/
  1088.  
  1089. void CWASTEText::SetStyle(short mode, TextStyle *newStyle, Boolean redraw)
  1090. {
  1091.     Boolean        saveAllocState;
  1092.     OSErr        err;
  1093.  
  1094.     Prepare();
  1095.     if (!ReallyVisible())
  1096.         SetOrigin(-10000, -10000);
  1097.     saveAllocState = SetAllocation(kAllocCanFail);
  1098.     err = WESetStyle( mode, newStyle, macWE);
  1099.     SetAllocation(saveAllocState);
  1100.  
  1101.     if (err == noErr)
  1102.     {
  1103.         SetSpacingCmd( spacingCmd);
  1104.         SetWholeLines( wholeLines);
  1105.     }
  1106.     AdjustBounds();
  1107.     FailOSErr(err);
  1108. }
  1109.  
  1110. /********************************************************\
  1111.  GetHeight - get the height of the indicated lines
  1112. \********************************************************/
  1113.  
  1114. long CWASTEText::GetHeight(long startLine, long endLine)
  1115. {
  1116.     long height;
  1117.     long nLines;
  1118.     
  1119.     nLines = GetNumLines();
  1120.     height = WEGetHeight( startLine - 1, endLine, macWE);
  1121.     if (endLine >= nLines && ((char*)(*GetTextHandle()))[GetLength()-1] == 13)
  1122.         height += WEGetHeight(nLines - 2, nLines - 1, macWE);
  1123.  
  1124.     return height;
  1125. }
  1126.  
  1127. /********************************************************\
  1128.  GetCharOffset - return offset of character at point in
  1129.      frame coords
  1130. \********************************************************/
  1131.  
  1132. long CWASTEText::GetCharOffset(LongPt *aPt)
  1133. {
  1134.     Point    qdPt;
  1135.     LongPt lPt;
  1136.     char edge;
  1137.     
  1138.     Prepare();
  1139.     FrameToQD( aPt, &qdPt);
  1140.     lPt.v = qdPt.v;
  1141.     lPt.h = qdPt.h;
  1142.     
  1143.     return WEGetOffset( &lPt, &edge, macWE);
  1144.     
  1145. }
  1146.  
  1147. /********************************************************\
  1148.  GetCharPoint - return the position of the character in
  1149.      Frame coordinates
  1150. \********************************************************/
  1151.  
  1152. void CWASTEText::GetCharPoint( long offset, LongPt *aPt)
  1153. {
  1154.     Point    qdPt;
  1155.     LongPt lPt;
  1156.     short lineHeight;
  1157.     
  1158.     ASSERT( offset <= MAXLONG);
  1159.     
  1160.     Prepare();
  1161.     WEGetPoint(offset, &lPt, &lineHeight, macWE);
  1162.     qdPt.h = lPt.h;
  1163.     qdPt.v = lPt.v;
  1164.     QDToFrame( qdPt, aPt);
  1165. }
  1166.  
  1167. /********************************************************\
  1168.  GetTextStyle - return style of selection
  1169. \********************************************************/
  1170.  
  1171. void CWASTEText::GetTextStyle(short *whichAttributes, TextStyle *aStyle)
  1172. {
  1173.     WEContinuousStyle(whichAttributes, aStyle, macWE);
  1174. }
  1175.  
  1176. StScrpHandle CWASTEText::GetTextStyles(void)
  1177. {
  1178.     OSErr            err;
  1179.     StScrpHandle    styles;
  1180.     Boolean            saveAllocState;
  1181.     
  1182.     styles = (StScrpHandle) NewHandleCanFail(0);
  1183.     saveAllocState = SetAllocation(kAllocCanFail);
  1184.     err = WECopyRange(0, WEGetTextLength(macWE), NULL, styles, macWE);
  1185.     SetAllocation(saveAllocState);
  1186.     if (err != noErr)
  1187.     {
  1188.         DisposeHandle((Handle) styles);
  1189.         FailOSErr(err);
  1190.     }
  1191.  
  1192.     return (styles);
  1193. }
  1194.  
  1195. /********************************************************\
  1196.  GetCharStyle - return style of one character
  1197. \********************************************************/
  1198.  
  1199. void CWASTEText::GetCharStyle(long charOffset, TextStyle *theStyle)
  1200. {
  1201.     WERunInfo runInfo;
  1202.  
  1203.     WEGetRunInfo(charOffset, &runInfo, macWE);
  1204.     *theStyle = runInfo.runStyle;
  1205. }
  1206.  
  1207. /********************************************************\
  1208.  GetSpacingCmd - not really supported
  1209. \********************************************************/
  1210.  
  1211. long CWASTEText::GetSpacingCmd(void)
  1212. {
  1213.     return spacingCmd;
  1214. }
  1215.  
  1216. /********************************************************\
  1217.  GetAlignCmd - not really supported
  1218. \********************************************************/
  1219.  
  1220. long CWASTEText::GetAlignCmd(void)
  1221. {
  1222.     return alignCmd;
  1223. }
  1224.  
  1225. /********************************************************\
  1226.  GetTheStyleScrap -- get a scrap handle of the styles
  1227.      of the selection
  1228. \********************************************************/
  1229.  
  1230. StScrpHandle CWASTEText::GetTheStyleScrap(void)
  1231. {
  1232.     Boolean        saveAllocState;
  1233.     OSErr        err;
  1234.     long        selStart, selEnd;
  1235.     StScrpHandle h;
  1236.  
  1237.     WEGetSelection(&selStart, &selEnd, macWE);
  1238.  
  1239.     h=(StScrpHandle)NewHandleCanFail(1);
  1240.     FailNIL(h);
  1241.     saveAllocState = SetAllocation(kAllocCanFail);
  1242.     err = WECopyRange(selStart, selEnd, (Handle)NULL, h, macWE);
  1243.     SetAllocation(saveAllocState);
  1244.     FailOSErr(err);
  1245.     
  1246.     return h;
  1247. }
  1248.  
  1249. /********************************************************\
  1250.  GetNumLines - return the number of lines
  1251. \********************************************************/
  1252.  
  1253. long CWASTEText::GetNumLines(void)
  1254. {
  1255.     long nLines = WECountLines(macWE);
  1256.  
  1257.     if (!GetLength()) return 0;
  1258.     if (((char*)(*GetTextHandle()))[GetLength()-1] == 13)
  1259.         nLines++;
  1260.     return nLines;
  1261. }
  1262.  
  1263. /********************************************************\
  1264.  GetSelection - get the position of the start and end
  1265.      of the selection
  1266. \********************************************************/
  1267.  
  1268. void CWASTEText::GetSelection(long *selStart, long *selEnd)
  1269. {
  1270.     WEGetSelection(selStart, selEnd, macWE);
  1271. }
  1272.  
  1273. /********************************************************\
  1274.  HideSelection - not implemented
  1275. \********************************************************/
  1276.  
  1277. void CWASTEText::HideSelection(Boolean hide, Boolean redraw)
  1278. {
  1279.     return;
  1280. }
  1281.  
  1282. /********************************************************\
  1283.  GetSteps - get the size of the scrolling steps
  1284.      Step sizes hard coded in
  1285. \********************************************************/
  1286.  
  1287. void CWASTEText::GetSteps(short *hStep, short *vStep)
  1288. {
  1289.     long        nLines,
  1290.                 height;
  1291.  
  1292.     nLines = GetNumLines();
  1293.     height = GetHeight(0, MAXINT);
  1294.     *hStep = 20;
  1295.     if (nLines)
  1296.         *vStep = Min(height / nLines, 30);
  1297.     else
  1298.         *vStep = height;
  1299. }
  1300.  
  1301. /********************************************************\
  1302.  AboutToPrint -- called right before printing
  1303. \********************************************************/
  1304.  
  1305. void CWASTEText::AboutToPrint(short *firstPage, short *lastPage)
  1306. {
  1307.     if (active)
  1308.     {
  1309.         Prepare();
  1310.         HidePen();
  1311.         WEDeactivate(macWE);
  1312.         ShowPen();
  1313.     }
  1314.  
  1315.     CAbstractText::AboutToPrint(firstPage, lastPage);
  1316. }
  1317.  
  1318.  
  1319. void CWASTEText::Paginate(CPrinter *aPrinter, short pageWidth, short pageHeight)
  1320. {
  1321.     Boolean        saveAllocState;
  1322.     OSErr        err;
  1323.     LongRect    dr;
  1324.  
  1325.     WEGetDestRect(&dr, macWE);
  1326.     dr.right = dr.left + pageWidth;
  1327.     WESetDestRect(&dr, macWE);
  1328.     saveAllocState = SetAllocation(kAllocCanFail);
  1329.     err = WECalText(macWE);
  1330.     SetAllocation(saveAllocState);
  1331.     FailOSErr(err);
  1332.     printPageWidth = pageWidth;
  1333.     
  1334.     CAbstractText::Paginate(aPrinter, pageWidth, pageHeight);
  1335. }
  1336.  
  1337.  
  1338. /********************************************************\
  1339.  PrintPage -- called to print page
  1340. \********************************************************/
  1341.  
  1342. void CWASTEText::PrintPage(short pageNum, short pageWidth, short pageHeight,
  1343.                            CPrinter *aPrinter)
  1344. {
  1345.     OSErr        err;
  1346.     short        oldOffscreen,
  1347.                 oldOutline;
  1348.  
  1349.     err = WESetInfo(wePort, (Ptr)&qd.thePort, macWE);
  1350.     // temporarily turn off off screen drawing and outline hiliting
  1351.     oldOffscreen = WEFeatureFlag(weFDrawOffscreen, weBitClear, macWE);
  1352.     oldOutline = WEFeatureFlag(weFOutlineHilite, weBitClear, macWE);
  1353.  
  1354. //    if (printClip == clipPAGE) {        /* Expand viewRect to the size of a    */
  1355. //                                        /*   page. It will be restored by    */
  1356. //                                        /*   the DonePrinting() method.        */
  1357. //        WEGetViewRect(&viewRect, macWE);
  1358. //        viewRect.right = viewRect.left + pageWidth;
  1359. //        
  1360. //        if (wholeLines) {
  1361. //            viewRect.bottom = viewRect.top +
  1362. //                                            vScale * (pageHeight / vScale);
  1363. //        } else {
  1364. //            viewRect.bottom = viewRect.top + pageHeight;
  1365. //        }
  1366. //        WESetViewRect(&viewRect, macWE);
  1367. //    }
  1368.  
  1369.     itsPrinter = aPrinter;
  1370.     CAbstractText::PrintPage(pageNum, pageWidth, pageHeight, aPrinter);
  1371.  
  1372.     err = WESetInfo(wePort, (Ptr)&macPort, macWE);
  1373.     WEFeatureFlag(weFDrawOffscreen, oldOffscreen, macWE);
  1374.     WEFeatureFlag(weFOutlineHilite, oldOutline, macWE);
  1375. }
  1376.  
  1377. /********************************************************\
  1378.  DonePrinting - called when printing is finished
  1379. \********************************************************/
  1380.  
  1381. void CWASTEText::DonePrinting()
  1382. {
  1383.     Boolean        saveAllocState;
  1384.     OSErr        err;
  1385.  
  1386.     CAbstractText::DonePrinting();
  1387.  
  1388.     if (active)
  1389.     {
  1390.         Prepare();
  1391.         HidePen();
  1392.         WEActivate(macWE);
  1393.         ShowPen();
  1394.     }
  1395.  
  1396.     TCL_ASSERT(itsPrinter);
  1397.     itsPrinter->ResetPagination();
  1398.     itsPrinter = NULL;
  1399.  
  1400.     CalcWERects();
  1401.     if (lineWidth < 0)
  1402.     {
  1403.         saveAllocState = SetAllocation(kAllocCanFail);
  1404.         err = WECalText( macWE);
  1405.         SetAllocation(saveAllocState);
  1406.     }
  1407. }
  1408.  
  1409. /********************************************************\
  1410.  Dawdle - do idle stuff
  1411. \********************************************************/
  1412.  
  1413. void CWASTEText::Dawdle(long *maxSleep)
  1414. {
  1415.     if (editable && visible)
  1416.     {
  1417.         Prepare();
  1418.         WEIdle(NULL, macWE);
  1419.         *maxSleep = GetCaretTime();
  1420.     }
  1421. }
  1422.  
  1423. /********************************************************\
  1424.  PutTo - not implemented
  1425. \********************************************************/
  1426.  
  1427. void CWASTEText::PutTo(CStream& stream)
  1428. {
  1429.     return;
  1430. }
  1431.  
  1432. /********************************************************\
  1433.  GetFrom - not implemented
  1434. \********************************************************/
  1435.  
  1436. void CWASTEText::GetFrom(CStream& stream)
  1437. {
  1438.     return;
  1439. }
  1440.  
  1441. /********************************************************\
  1442.  WEClickLoop - click loop routine
  1443. \********************************************************/
  1444.  
  1445. static pascal Boolean    WEClickLoop(WEHandle hWE)
  1446. {
  1447.     Point        mouseLoc;
  1448.     LongPt        longMouse;
  1449.  
  1450.     if (gWASTEText != NULL) {
  1451.         GetMouse(&mouseLoc);
  1452.         gWASTEText->QDToFrame(mouseLoc, &longMouse);
  1453.         gWASTEText->AutoScroll( &longMouse);
  1454.     }
  1455.     return(TRUE);
  1456. }
  1457.  
  1458. // static variables for the following routines
  1459. static Boolean wasActive, outlineHilite;
  1460. static long selStart, selEnd;
  1461.  
  1462. /********************************************************\
  1463.  TempSelectAll -- temporarily selects all of the text
  1464.      while deactivating the text and turning off 
  1465.      outline hilighting so that the selection won't show
  1466.      up.  It can be restored by Restore selection.  This
  1467.      is useful when you want to apply something to all
  1468.      of the text without seeing all of the text flash.
  1469.      
  1470.      Note: Calls to TempSelectAll/RestoreSelection cannot
  1471.      be nested
  1472. \********************************************************/
  1473.  
  1474. void CWASTEText::TempSelectAll(void)
  1475. {
  1476.     // turn off outline highlighting temporarily
  1477.     outlineHilite = SetOutlineHighliting(false);
  1478.  
  1479.     // deactivate text
  1480.     wasActive = active;
  1481.     if (wasActive) Deactivate();
  1482.     
  1483.     // select all
  1484.     GetSelection(&selStart, &selEnd);
  1485.     SetSelection(0, 0x7FFFFFF, false);
  1486. }
  1487.     
  1488. /********************************************************\
  1489.  RestoreSelection - restores things to the way they
  1490.      were before a call to TempSelectAll()
  1491. \********************************************************/
  1492.  
  1493. void CWASTEText::RestoreSelection(void)
  1494. {
  1495.     if (wasActive) Activate();
  1496.     SetOutlineHighliting(outlineHilite);
  1497.     SetSelection(selStart, selEnd, false);
  1498. }
  1499.  
  1500. /******************************************************************************
  1501.  Specify
  1502.  
  1503.     If editable is changed and it's active, enable/disable TSMInput
  1504.  ******************************************************************************/
  1505.  
  1506. void CWASTEText::Specify(Boolean fEditable, Boolean fSelectable, Boolean fStylable)
  1507. {
  1508.     Boolean wasEditable = editable;
  1509.     TSMDocumentID aTSMDocument;
  1510.     
  1511.     inherited::Specify(fEditable, fSelectable, fStylable);
  1512.  
  1513.     if (active && wasEditable && !editable)
  1514.     {
  1515.         // if not editable, deactivate TSM so inline input won't work
  1516.         if (gUsingTSM)
  1517.         {
  1518.             if (WEGetInfo(weTSMDocumentID, (Ptr)&aTSMDocument, macWE) == noErr)
  1519.             {
  1520.                 if (aTSMDocument != NULL)
  1521.                     DeactivateTSMDocument(aTSMDocument);
  1522.             }
  1523.         }
  1524.     }
  1525.  
  1526.     if (active && !wasEditable && editable)
  1527.     {
  1528.         // if not editable, deactivate TSM so inline input won't work
  1529.         if (gUsingTSM)
  1530.         {
  1531.             if (WEGetInfo(weTSMDocumentID, (Ptr)&aTSMDocument, macWE) == noErr)
  1532.             {
  1533.                 if (aTSMDocument != NULL)
  1534.                     ActivateTSMDocument(aTSMDocument);
  1535.             }
  1536.         }
  1537.     }
  1538.  
  1539.  
  1540.  
  1541. }
  1542.  
  1543.  
  1544.  
  1545.